package com.xaicode.template.activemq.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class JMS_produce_topic_test {

    public static final String ACTIVEMQ_URL = "tcp://192.168.18.182:61616";
    public static final String TOPIC_NAME = "CRZS_TRANSFER_SYSTEM";

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = activeMQConnectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(TOPIC_NAME);
        MessageProducer producer = session.createProducer(topic);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        connection.start();
        String msg = "{\"IEMsgHeader\":{\"MsgType\":\"CRZS_AUTHENTICATE_REQ\",\"IeType\":1},\"IEUserInfo\":{\"UserName\":\"wang\"" +
                ",\"UserPwd\":\"123456\"}}";
        MapMessage mapMessage = session.createMapMessage();
        mapMessage.setObject("Msg", msg);
        producer.send(mapMessage);

        producer.close();
        session.close();
        connection.close();

        System.out.println("持久化TOPIC消息发送完成");
    }
}
